﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DormMS.IService;
using DormMS.Model;
using DormMS.Model.ViewModels;
using Infrastructure.Dao;
using SqlSugar;

namespace DormMS.Service
{
    public class ClassService : IClassService
    {
        private SqlSugarClient db;

        public List<V_Class> getClassAllList()
        {
            using (db = DbConfig.GetInstance())
            {
                db.CurrentFilterKey = "";
                var data = db.Queryable<Class>().JoinTable<Department>((m, s2) => m.DepartmentId == s2.Id).JoinTable<UserInfo>((m, s3) => m.TeacherId == s3.Id, JoinType.Left).Select<Class, Department, UserInfo, V_Class>((m, s2, s3) => new V_Class { Id = m.Id, ClassName = m.ClassName, DepartmentId = m.DepartmentId, DepartmentName = s2.DepartmentName, TeacherId = s3.Id }).ToList();
                return data;
            }
        }

        public List<V_Class> getClassList(int departmentID)
        {
            
            using(db = DbConfig.GetInstance())
            {
                db.CurrentFilterKey = "";
                var data = db.Queryable<Class>().Where(x => x.DepartmentId == departmentID).JoinTable<Department>((m,s2) => m.DepartmentId == s2.Id).JoinTable<UserInfo>((m,s3) => m.TeacherId==s3.Id, JoinType.Left).Select<Class, Department,UserInfo,V_Class>((m,s2,s3) => new V_Class { Id = m.Id, ClassName = m.ClassName,DepartmentId = m.DepartmentId, DepartmentName = s2.DepartmentName, TeacherId = s3.Id, TeacherName = s3.RealName  }).ToList();
                return data;
            }

        }
    }
}
